package com.lyz.dataStructure.algorithm.jingdong2020;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 19:56
 * @Description:
 **/

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/8/24 19:56
 *@Description:
 **/
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap map = new HashMap();
        long N = sc.nextLong();
        long[] arr = new long[(int) N];
        for(int i =0;i<arr.length;i++){
            arr[i] = sc.nextLong();
        }
        for(int i = 0;i<arr.length;i++){
            map.put(arr[i],i);
        }
        Arrays.sort(arr,0,arr.length);
        /*
        4
        2 1 3 2
        1 2 2 3
         */
        long count = 0;
        for(int i =0;i<arr.length-1;i++){
            if(map.get(arr[i])==map.get(arr[i+1]+1)||map.get(arr[i])==map.get(arr[i+1]-1)){
                count++;
            }else {
                count = count ;
            }
        }
        System.out.println(count);
    }
}
